package my.bc.webdav.model;

public class DavNodeXmlRepresentor implements DavNodeRepresentor
{
  private XmlFormatter formatter = new XmlFormatter();
  
  @SuppressWarnings( "unchecked")
  @Override
  public String represent( DavNode node )
  {
    StringBuilder xml = new StringBuilder();
    xml.append( formatter.getIndented() + "<" + node.getNodeType() + " name=" + node.getName() + ">" + formatter.getTagSeperator() );
    if( node instanceof Composite )
    {
      formatter.increaseDepth();
      for( DavNode child : ((Composite<DavNode>)node).getChildren() )
      {
        xml.append( represent( child ) );
      }
      formatter.decreaseDepth();
    }
    xml.append( formatter.getIndented() + "</" + node.getNodeType() + ">" + formatter.getTagSeperator() );
    return xml.toString();
  }

}
